package com.endoc.phtotapplication.utils;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.endoc.phtotapplication.R;

public class VerifyUtils {
    public static   void verifyResult(AppCompatActivity activity, View parent, String name, boolean isSuccess){
        PopupWindow popupBigPhoto = null;

        //PopupWindow的布局
        View view = activity.getLayoutInflater().inflate(R.layout.layout_verify, null);

        ImageView imShow = (ImageView) view.findViewById(R.id.im_show);
        TextView tvNotify = (TextView) view.findViewById(R.id.tv_notify);
        TextView  tvName = (TextView) view.findViewById(R.id.tv_name);

        if(isSuccess){
            imShow.setImageResource(R.drawable.tc_cg_img);
            tvNotify.setText("对比成功");
            tvName.setText(name);
        }else {
            imShow.setImageResource(R.drawable.tc_rzsb_img);
            tvNotify.setText(" 很抱歉，认证失败！");
            tvName.setText("请联系管理员或重试");
        }

        if (popupBigPhoto == null) {
            popupBigPhoto = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
            popupBigPhoto.setOutsideTouchable(true);
            popupBigPhoto.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {

                }
            });
        }
        if (popupBigPhoto.isShowing()) {
            popupBigPhoto.dismiss();
        } else {
            //findViewById(R.id.cl_root)  popupWindows需要显示的控件上
            //popupBigPhoto.showAtLocation(findViewById(R.id.cl_root), Gravity.BOTTOM, 0, 0);
            popupBigPhoto.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        }
    }
}
